package com.eshop.utils;

import java.io.InputStream;
import java.io.IOException;
import java.awt.FontFormatException;
import java.io.FileInputStream;
import java.io.File;
import java.awt.Font;

public class FontUtil
{
    public static final int DEFAULT_FONT = 1;
    public static final int PINGFANG_FONT = 2;
    public static final int PINGFANG_BOLD_FONT = 3;
    public static final int FZLTTH_GBK_FONT = 4;
    
    public static Font getFont(final int type, final float size) {
        String path = "";
        switch (type) {
            case 1: {
                path = "D:/upload/resources/font/simhei.ttf";
                break;
            }
            case 2: {
                path = "D:/upload/resources/font/PingFangSC.ttf";
                break;
            }
            case 3: {
                path = "D:/upload/resources/font/PingFangBold.ttf";
                break;
            }
            case 4: {
                path = "D:/upload/resources/font/fzltthjwgb10.ttf";
                break;
            }
            default: {
                path = "D:/upload/resources/font/simhei.ttf";
                break;
            }
        }
        final File file = new File(path);
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            Font sPfBoldFont = Font.createFont(0, inputStream);
            sPfBoldFont = sPfBoldFont.deriveFont(size);
            return sPfBoldFont;
        }
        catch (FontFormatException e) {
            e.printStackTrace();
        }
        catch (IOException e2) {
            e2.printStackTrace();
        }
        finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            }
            catch (Exception e3) {
                e3.printStackTrace();
            }
        }
        return null;
    }
}
